package struts.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import struts.model.User;

@Component
public class UserDAO {
	private HibernateTemplate hibernateTemplate;

	public void save(User user) {
		hibernateTemplate.save(user);
	}
	
	public void delete(User user) {
		hibernateTemplate.delete(user);
	}
	
	public void update(User user) {
		hibernateTemplate.update(user);
	}
	
	public User load(int id) {
		User user = new User();
		hibernateTemplate.load(user, id);
		return user;
	}
	
	public List<User> loadAll() {
		List<User> users = new ArrayList<User>();
		users = hibernateTemplate.loadAll(User.class);
		return users;
	}
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
